package com.couldsail.takeaway.pojo.vo;


import com.couldsail.takeaway.constant.OrdersConstant;
import com.couldsail.takeaway.pojo.entity.OrderDetail;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "订单VO")
public class OrderVO {
    @Schema(description = "订单id")
    private String id;

    @Schema(description = "餐具数量")
    private Integer tablewareNumber;

    @Schema(description = "桌号")
    private String seatNums;

    @Schema(description = "0 堂食 1 外卖")
    private Integer seatStatus;

    @Schema(description = "备注")
    private String remark;
    
    @Schema(description = "收货人")
    private String consignee;
    
    @Schema(description = "手机号")
    private String phone;
    
    @Schema(description = "地址")
    private String address;

    @Schema(description = "商品总金额")
    private Double totalAmount;


    @Schema(description = "实收金额")
    private BigDecimal amount;

    @Schema(description = "商品数量")
    private int totalNumber;

    @Schema(description = "订单明细")
    private List<OrderDetail> orderDetails;

    @Schema(description = "店铺详情")
    private ShopVO shopDetail;

    @Schema(description = "支付方式 1微信,2支付宝")
    private Object payMethod;

    @Schema(description = "订单其他费用明细")
    private List<OrderDetail> orderDetailOthers;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @Schema(description = "下单时间")
    private LocalDateTime orderTime;

    @Schema(description = "订单状态")
    private String status;
    private static final Map<Integer, String> statusMap;
    private static final Map<Integer, String> payMethodMap;

    static {
        statusMap = new HashMap<>();
        statusMap.put(OrdersConstant.ORDER_STATUS_WAIT_PAY, "待付款");
        statusMap.put(OrdersConstant.ORDER_STATUS_WAIT_ACCEPT, "待接单");
        statusMap.put(OrdersConstant.ORDER_STATUS_ACCEPTED, "已接单");
        statusMap.put(OrdersConstant.ORDER_STATUS_DELIVERING, "派送中");
        statusMap.put(OrdersConstant.ORDER_STATUS_COMPLETED, "已完成");
        statusMap.put(OrdersConstant.ORDER_STATUS_CANCELLED, "已取消");
        statusMap.put(OrdersConstant.ORDER_STATUS_REFUNDED, "退款");
    }
    static {
        payMethodMap = new HashMap<>();
        payMethodMap.put(OrdersConstant.PAY_METHOD_WECHAT, "微信");
        payMethodMap.put(OrdersConstant.PAY_METHOD_ALIPAY, "支付宝");
        payMethodMap.put(OrdersConstant.PAY_METHOD_CASH, "现金");
    }
    public void setStatus(Integer statusCode) {
        this.status = statusMap.getOrDefault(statusCode, "未知状态");
    }
    public void setPayMethod(Integer payMethodCode) {
        this.payMethod = payMethodMap.getOrDefault(payMethodCode, "未知状态");
    }

}